home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 30 / Mac Magazin and MacEasy Magazine CD - Issue 30.iso / utilities / Mac OS X / Load_Monitor / src / AboutBox / AboutBox.m < prev   
Encoding:
Text File  |  2002-01-14  |  5.8 KB  |  181 lines

  1. /*
  2.  
  3. http://www.cocoadevcentral.com/tutorials/
  4.  
  5. */
  6.  
  7. #import "AboutBox.h"
  8.  
  9. @implementation AboutBox
  10.  
  11. static AboutBox *sharedInstance = nil;
  12.  
  13. + (AboutBox *)sharedInstance
  14. {
  15.     return sharedInstance ? sharedInstance : [[self alloc] init];
  16. }
  17.  
  18. - (id)init 
  19. {
  20.     if (sharedInstance) {
  21.         [self dealloc];
  22.     } else {
  23.         sharedInstance = [super init];
  24.     }
  25.     
  26.     return sharedInstance;
  27. }
  28.  
  29. - (IBAction)showPanel:(id)sender
  30. {
  31.     if (!appNameField)
  32.     {
  33.         NSWindow *theWindow;
  34.         NSString *creditsPath;
  35.         NSAttributedString *creditsString;
  36.         NSString *appName;
  37.         NSString *versionString;
  38.         NSString *copyrightString;
  39.         NSDictionary *infoDictionary;
  40.         CFBundleRef localInfoBundle;
  41.         NSDictionary *localInfoDict;
  42.         
  43.         NSDictionary *GlobalPreferences;
  44.         NSArray *mainlanguage;
  45.  
  46.         if (![NSBundle loadNibNamed:@"AboutBox" owner:self])
  47.         {
  48.                 // int NSRunCriticalAlertPanel(NSString *title, 
  49.                 //              NSString *msg, NSString *defaultButton, 
  50.                 //              NSString *alternateButton, NSString *otherButton, ...);
  51.                 
  52.             NSLog( @"Failed to load AboutBox.nib" );
  53.             NSBeep();
  54.             return;
  55.         }
  56.  
  57.         theWindow = [appNameField window];
  58.         
  59.         // Get the info dictionary (Info.plist)
  60.         infoDictionary = [[NSBundle mainBundle] infoDictionary];
  61.  
  62.         // Get the localized info dictionary (InfoPlist.strings)
  63.         localInfoBundle = CFBundleGetMainBundle();
  64.         localInfoDict = (NSDictionary *)
  65.                         CFBundleGetLocalInfoDictionary( localInfoBundle );
  66.  
  67.         // Setup the app name field
  68.         appName = [localInfoDict objectForKey:@"CFBundleName"];
  69.         [appNameField setStringValue:appName];
  70.         
  71.         // determination of the main language and Set the about box window title
  72.         GlobalPreferences = [[NSDictionary dictionaryWithContentsOfFile: [@"~/Library/Preferences/.GlobalPreferences.plist" 
  73.         stringByExpandingTildeInPath]] retain];
  74.         mainlanguage = [GlobalPreferences objectForKey: @"AppleLanguages"];
  75.         if([[[mainlanguage objectAtIndex:0] retain] isEqualToString:@"English"])
  76.             [theWindow setTitle:[NSString stringWithFormat:@"About %@", appName]];
  77.         else if([[[mainlanguage objectAtIndex:0] retain] isEqualToString:@"French"])
  78.             [theWindow setTitle:[NSString stringWithFormat:@"À propos de %@", appName]];
  79.     else if([[[mainlanguage objectAtIndex:0] retain] isEqualToString:@"German"])
  80.             [theWindow setTitle:[NSString stringWithFormat:@"Über %@", appName]];
  81.     else
  82.             [theWindow setTitle:[NSString stringWithFormat:@"About %@", appName]];
  83.                 
  84.         // Set the about box window title
  85.         //[theWindow setTitle:[NSString stringWithFormat:@"About %@", appName]];
  86.         
  87.         // Setup the version field
  88.         versionString = [infoDictionary objectForKey:@"CFBundleVersion"];
  89.         [versionField setStringValue:[NSString stringWithFormat:@"Version %@", 
  90.                                                           versionString]];
  91.  
  92.         // Setup our credits
  93.         creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" 
  94.                                              ofType:@"rtf"];
  95.  
  96.         creditsString = [[NSAttributedString alloc] initWithPath:creditsPath 
  97.                                                     documentAttributes:nil];
  98.         
  99.         [creditsField replaceCharactersInRange:NSMakeRange( 0, 0 ) 
  100.                       withRTF:[creditsString RTFFromRange:
  101.                                NSMakeRange( 0, [creditsString length] ) 
  102.                                              documentAttributes:nil]];
  103.  
  104.         // Setup the copyright field
  105.         copyrightString = [localInfoDict objectForKey:@"NSHumanReadableCopyright"];
  106.         [copyrightField setStringValue:copyrightString];
  107.         
  108.         // Prepare some scroll info
  109.         maxScrollHeight = [[creditsField string] length];
  110.         
  111.         // Setup the window
  112.         [theWindow setExcludedFromWindowsMenu:YES];
  113.         [theWindow setMenu:nil];
  114.         [theWindow center];
  115.     }
  116.  
  117.     if (![[appNameField window] isVisible])
  118.     {
  119.         currentPosition = 0;
  120.         restartAtTop = NO;
  121.         startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
  122.         [creditsField scrollPoint:NSMakePoint( 0, 0 )];
  123.     }
  124.     
  125.     // Show the window
  126.     [[appNameField window] makeKeyAndOrderFront:nil];
  127. }
  128.  
  129. - (void)windowDidBecomeKey:(NSNotification *)notification
  130. {
  131. /*    scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1/4 
  132.                            target:self 
  133.                            selector:@selector(scrollCredits:) 
  134.                            userInfo:nil 
  135.                            repeats:YES];*/
  136. }
  137. /*
  138. - (void)windowDidResignKey:(NSNotification *)notification
  139. {
  140.     [scrollTimer invalidate];
  141. }
  142.  
  143. - (void)scrollCredits:(NSTimer *)timer
  144. {
  145.     if ([NSDate timeIntervalSinceReferenceDate] >= startTime)
  146.     {
  147.         if (restartAtTop)
  148.         {
  149.             // Reset the startTime
  150.             startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
  151.             restartAtTop = NO;
  152.             
  153.             // Set the position
  154.             [creditsField scrollPoint:NSMakePoint( 0, 0 )];
  155.             
  156.             return;
  157.         }
  158.  
  159.         if (currentPosition >= maxScrollHeight) 
  160.         {
  161.             // Reset the startTime
  162.             startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
  163.             
  164.             // Reset the position
  165.             currentPosition = 0;
  166.             restartAtTop = YES;
  167.         }
  168.         else
  169.         {
  170.             // Scroll to the position
  171.             [creditsField scrollPoint:NSMakePoint( 0, currentPosition )];
  172.             
  173.             // Increment the scroll position
  174.             currentPosition += 0.01;
  175.         }
  176.     }
  177. }*/
  178.  
  179. @end
  180.  
  181.